using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
using System.Diagnostics;

namespace Perovich.GameObjects.ThreeDimensional
{
    /*
    public class BoundingSphereImage : WireframeModelObject3D
    {

        public BoundingSphereImage(Interfaces.ICanHoldComponents game)
            : base(game)
        {
        }
        

        
        
        private VertexPositionColor[] vpnt;
        private int slices;

        int polygons;
        BasicEffect basicEffect;

        public int Slices
        {
            get { return slices; }
            set
            {
                slices = 2*value;
                Tesellate();
            }
        }
        private int stacks;

        public int Stacks
        {
            get { return stacks; }
            set
            {
                stacks = 2*value;
                Tesellate();
            }
        }

        private Color _color;

        public Color BBColor
        {
            get { return _color; }
            set
            {
                _color = value;
                Tesellate();
            }
        }


        private short[] indices;
        public BoundingSphereImage(Game game)
            : base(game)
        {
            slices = 12;
            stacks = 6;
            ScaleChanged += new EventHandler(BoundingSphereTest_ScaleChanged);
            //Tesellate();
            BBColor = Color.White;
        }

        protected override void LoadContent()
        {
            basicEffect = new BasicEffect(GraphicsDevice);
            base.LoadContent();
        }



        void BoundingSphereTest_ScaleChanged(object sender, EventArgs e)
        {
            Tesellate();
        }


        


        protected void expTesellate()
        {
            vpnt = new VertexPositionColor[(slices + 1) * (stacks + 1)];

            float phi, theta;
            float dphi = MathHelper.TwoPi / slices;
            float dtheta = MathHelper.Pi / stacks;
            float x, y, z;
            float sinthe, costhe;
            float sinphi, cosphi;
            int index = 0;

            for (int stack = 0; stack <= stacks; stack++)
            {
                theta = stack * dtheta;
                sinthe = (float)Math.Sin(theta);
                costhe = (float)Math.Cos(theta);
                z = Scale * costhe;
                for (int slice = 0; slice < slices; slice++)
                {
                    phi = slice * dphi;
                    sinphi = (float)Math.Sin(phi);
                    cosphi = (float)Math.Cos(phi);
                    x = Scale * cosphi * sinthe;
                    y = Scale * sinphi * sinthe;

                    vpnt[index++] = new VertexPositionColor(new Vector3(x, y, z),
                        BBColor);
                }
            }

            indices = new short[(slices + 1) * stacks * 2];
            index = 0;
            int k = slices + 1;

            for (int stack = 0; stack < stacks; stack++)
            {
                for (int slice = 0; slice <= slices; slice++)
                {
                    indices[index++] = (short)((stack * slices) + (slice % slices));
                    indices[index++] = (short)(((stack + 1) * slices) + (slice % slices));
                }
            }
        }


        protected void Tesellate()
        {
            vpnt = new VertexPositionColor[slices* (stacks+2)];

            float phi, theta;
            float dphi = MathHelper.TwoPi / slices;
            float dtheta = MathHelper.Pi / stacks;
            float x, y, z;
            float sinthe, costhe;
            float sinphi, cosphi;
            int index = 0;

            theta = 0;
            sinthe = (float)Math.Sin(theta);
            costhe = (float)Math.Cos(theta);
            z = Scale * costhe;
            for (int slice = 0; slice < slices; slice++)
            {
                phi = slice * dphi;
                sinphi = (float)Math.Sin(phi);
                cosphi = (float)Math.Cos(phi);
                x = Scale * cosphi * sinthe;
                y = Scale * sinphi * sinthe;

                vpnt[index++] = new VertexPositionColor(new Vector3(x, y, z),
                    BBColor);
            }

            for (int stack = 0; stack <= stacks; stack++)
            {
                for (int slice = 0; slice < slices; slice++)
                {
                    theta = (float)((stack * Math.PI / stacks) + ((Math.PI * slice) / (slices * stacks)));
                    if (stack == stacks)
                    {
                        theta = (float)Math.PI;
                    }
                    phi = (float)(slice * 2 * Math.PI / slices);
                    sinthe = (float)Math.Sin(theta);
                    costhe = (float)Math.Cos(theta);
                    sinphi = (float)Math.Sin(phi);
                    cosphi = (float)Math.Cos(phi);

                    x = Scale * cosphi * sinthe;
                    y = Scale * sinphi * sinthe;
                    z = Scale * costhe;
                    vpnt[index++] = new VertexPositionColor(new Vector3(x, y, z),
                        BBColor);

                }
            }


            indices = new short[(slices * (stacks + 1) )*2];
            index = 0;
            int k = slices + 1;


            for (int slice = 0; slice < slices; slice++)
            {
                indices[index++] = (short)(slice);
                indices[index++] = (short)(slice+slices);
            }

            for (int stack = 0; stack < stacks; stack++)
            {
                for (int slice = 0; slice < slices; slice++)
                {
                    indices[index++] = (short)(((stack + 1) * slices) + slice);
                    indices[index++] = (short)(((stack + 2) * slices) + slice);
                }
            }
        }


        short get_index(int stack, int slice, int k, int stacks)
        {
            slice = slice % k;
            if (stack == 0)
            {
                return 0;
            }
            if (stack == stacks)
            {
                return (short)((k * (stacks - 1) + 2) - 1);
            }
            return (short)((stack - 1) * k + slice + 1);
        }

        public override void Draw(GameTime gameTime)
        {
            RasterizerState rs = new RasterizerState();
            rs.FillMode = FillMode.WireFrame;
            rs.CullMode = CullMode.CullClockwiseFace;
            GraphicsDevice.RasterizerState = rs;

            Matrix translateMatrix = Matrix.CreateTranslation(Position);
            Matrix rotationMatrix = Matrix.CreateRotationY(_rotationY) * Matrix.CreateRotationX(_rotationX);
            Matrix worldMatrix = rotationMatrix * translateMatrix;

            basicEffect.VertexColorEnabled = true;
            basicEffect.World = worldMatrix;

            foreach (Camera c in Cameras)
            {
                basicEffect.View = c.ViewMatrix;
                basicEffect.Projection = c.ProjectionMatrix;
                foreach (EffectPass pass in basicEffect.CurrentTechnique.Passes)
                {
                    pass.Apply();

                    GraphicsDevice.DrawUserIndexedPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, vpnt, 0, vpnt.Length, indices, 0, indices.Length-2, VertexPositionColor.VertexDeclaration);
                }
            }

            rs = new RasterizerState();
            rs.FillMode = FillMode.Solid;
            GraphicsDevice.RasterizerState = rs;
            base.Draw(gameTime);
        }

        
    }*/
}
